package com.example.yls.demoa;

import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private MySqLiteOpenHelper mySqLiteOpenHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //打开数据库
        findViewById(R.id.btn_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mySqLiteOpenHelper = new MySqLiteOpenHelper(MainActivity.this,
                        "stu.db",null,2);
                SQLiteDatabase db = mySqLiteOpenHelper.getWritableDatabase();
                db.close();
            }
        });

        //插入数据
        findViewById(R.id.btn_insert).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLiteDatabase db = mySqLiteOpenHelper.getWritableDatabase();
                String sql = "insert into student values('17001','zs',20)";
                db.execSQL(sql);
                db.close();
            }
        });
    }
}
